﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace DynamicQuartz.Common
{
    public class QyWeChatNotification
    {
        public static void Notification(string msg, string key)
        {
            var urlls = new List<string>
            {
                $"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={key}",
            };

            foreach (var item in urlls)
            {
                var client = new HttpClient();
                var request = new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    RequestUri = new Uri(item),
                    Content = new StringContent(msg)
                    {
                        Headers =
                    {
                        ContentType = new MediaTypeHeaderValue("application/json")
                    }
                    }
                };
                using (var response = client.SendAsync(request).Result)
                {
                    response.EnsureSuccessStatusCode();
                    var body = response.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(body);
                }
            }
        }
    }
}
